package org.example.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.entity.Order;
import org.example.exception.MyException;
import org.example.service.AircraftService;
import org.example.service.IBoatService;
import org.example.service.IPubService;
import org.example.service.OrderService;
import org.example.service.yy.AttractionsService;
import org.example.utils.Result;
import org.example.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@Api(tags = "订单管理")
@RestController
@CrossOrigin
public class OrderController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private AircraftService aircraftService;
    @Autowired
    private AttractionsService attractionsService;
    @Autowired
    private IPubService pubService;

    @ApiOperation("获取当前用户的订单集合")
    @GetMapping("get-order-list")
    public Result getOrderList(Integer type){
        List<Order> orderList = orderService.getOrderList(Math.toIntExact(ThreadLocalUtil.getCurrentId()),type);
        return new Result<>("200","查询成功",orderList);
    }

    @ApiOperation("添加订单")
    @PostMapping("insert-order")
    public Result insertOrder(@RequestBody Order order){
        if (orderService.insertOrder(order)<=0)
            throw new MyException("444","添加失败");
        return new Result<>("200","添加成功");
    }

    @ApiOperation("添加景点订单")
    @GetMapping("insert-scenic-order")
    public Result getOrderById(@RequestParam("uid") Integer uid,
                               @RequestParam("orderNumber") Long orderNumber,
                               @RequestParam("orderName") String orderName,
                               @RequestParam("price") double price){
        if (orderService.insertScenicOrder(Math.toIntExact(ThreadLocalUtil.getCurrentId()),orderNumber,orderName,price)<=0){
            throw new MyException("444","添加失败");
        }else {
            return new Result<>("200","添加成功");
        }
    }
}
